package com.corgi.message.kafka.controller;

import com.corgi.message.kafka.domain.User;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @title: KafkaController
 * @description:
 * @author: dengmiao
 * @create: 2019-10-10 17:31
 **/
@RestController
public class KafkaController {

	private final KafkaTemplate<String, Object> kafkaTemplate;

	public KafkaController(final KafkaTemplate kafkaTemplate) {
		this.kafkaTemplate = kafkaTemplate;
	}

	@GetMapping(value = "/message/send")
	public String sendMessage(@RequestParam String message) {
		kafkaTemplate.send("sf-2", "0", message);
		return message;
	}

	@PostMapping(value = "/user/save")
	public User saveUser(@RequestBody User user) {
		kafkaTemplate.send("sf-users", "0", user);
		return user;
	}
}
